Skip to main content

API Overview

Classes​

Functions​

function init​

Initialize weave tracking, logging to a wandb project. Logging is initialized globally, so you do not need to keep a reference to the return value of init. Following init, calls of weave.op() decorated functions will be logged to the specified project. Args:
  • project_name**: The name of the Weights & Biases project to log to.
  • settings: Configuration for the Weave client generally.
  • autopatch_settings: Configuration for autopatch integrations, e.g. openai
  • global_postprocess_inputs: A function that will be applied to all inputs of all ops.
  • global_postprocess_output: A function that will be applied to all outputs of all ops.
  • global_attributes: A dictionary of attributes that will be applied to all traces.
NOTE: Global postprocessing settings are applied to all ops after each op’s own postprocessing. The order is always: 1. Op-specific postprocessing 2. Global postprocessing Returns: A Weave client.

function publish​

Save and version a python object. If an object with name already exists, and the content hash of obj does not match the latest version of that object, a new version will be created. TODO: Need to document how name works with this change. Args:
  • obj**: The object to save and version.
  • name: The name to save the object under.
Returns: A weave Ref to the saved object.

function ref​

Construct a Ref to a Weave object. TODO: what happens if obj does not exist Args:
  • location**: A fully-qualified weave ref URI, or if weave.init() has been called, “name:version” or just “name” (“latest” will be used for version in this case).
Returns: A weave Ref to the object.

function get​

A convenience function for getting an object from a URI. Many objects logged by Weave are automatically registered with the Weave server. This function allows you to retrieve those objects by their URI. Args:
  • uri**: A fully-qualified weave ref URI.
Returns: The object. Example:

function require_current_call​

Get the Call object for the currently executing Op, within that Op. This allows you to access attributes of the Call such as its id or feedback while it is running.
It is also possible to access a Call after the Op has returned. If you have the Call’s id, perhaps from the UI, you can use the get_call method on the WeaveClient returned from weave.init to retrieve the Call object.
Alternately, after defining your Op you can use its call method. For example:
Returns: The Call object for the currently executing Op Raises:
  • NoCurrentCallError**: If tracking has not been initialized or this method is invoked outside an Op.

function get_current_call​

Get the Call object for the currently executing Op, within that Op. Returns: The Call object for the currently executing Op, or None if tracking has not been initialized or this method is invoked outside an Op.

function finish​

Stops logging to weave. Following finish, calls of weave.op() decorated functions will no longer be logged. You will need to run weave.init() again to resume logging.

function op​

A decorator to weave op-ify a function or method. Works for both sync and async. Automatically detects iterator functions and applies appropriate behavior.

function attributes​

Context manager for setting attributes on a call. Attributes become immutable once a call begins execution. Use this context manager to provide metadata before the call starts. Example:

class Object​

Pydantic Fields:
  • name: typing.Optional[str]
  • description: typing.Optional[str]
  • ref: typing.Optional[trace.refs.ObjectRef]

classmethod from_uri​

classmethod handle_relocatable_object​

class Dataset​

Dataset object with easy saving and automatic versioning Examples:
Pydantic Fields:
  • name: typing.Optional[str]
  • description: typing.Optional[str]
  • ref: typing.Optional[trace.refs.ObjectRef]
  • rows: typing.Union[trace.table.Table, trace.vals.WeaveTable]

method add_rows​

Create a new dataset version by appending rows to the existing dataset. This is useful for adding examples to large datasets without having to load the entire dataset into memory. Args:
  • rows**: The rows to add to the dataset.
Returns: The updated dataset.

classmethod convert_to_table​

classmethod from_calls​

classmethod from_obj​

classmethod from_pandas​

method select​

Select rows from the dataset based on the provided indices. Args:
  • indices**: An iterable of integer indices specifying which rows to select.
Returns: A new Dataset object containing only the selected rows.

method to_pandas​

class Model​

Intended to capture a combination of code and data the operates on an input. For example it might call an LLM with a prompt to make a prediction or generate text. When you change the attributes or the code that defines your model, these changes will be logged and the version will be updated. This ensures that you can compare the predictions across different versions of your model. Use this to iterate on prompts or to try the latest LLM and compare predictions across different settings Examples:
Pydantic Fields:
  • name: typing.Optional[str]
  • description: typing.Optional[str]
  • ref: typing.Optional[trace.refs.ObjectRef]

method get_infer_method​

class Prompt​

Pydantic Fields:
  • name: typing.Optional[str]
  • description: typing.Optional[str]
  • ref: typing.Optional[trace.refs.ObjectRef]

method format​

class StringPrompt​

method __init__​

Pydantic Fields:
  • name: typing.Optional[str]
  • description: typing.Optional[str]
  • ref: typing.Optional[trace.refs.ObjectRef]
  • content: “

method format​

classmethod from_obj​

class MessagesPrompt​

method __init__​

Pydantic Fields:
  • name: typing.Optional[str]
  • description: typing.Optional[str]
  • ref: typing.Optional[trace.refs.ObjectRef]
  • messages: list[dict]

method format​

method format_message​

classmethod from_obj​

class Evaluation​

Sets up an evaluation which includes a set of scorers and a dataset. Calling evaluation.evaluate(model) will pass in rows from a dataset into a model matching the names of the columns of the dataset to the argument names in model.predict. Then it will call all of the scorers and save the results in weave. If you want to preprocess the rows from the dataset you can pass in a function to preprocess_model_input. Examples:
Pydantic Fields:
  • name: typing.Optional[str]
  • description: typing.Optional[str]
  • ref: typing.Optional[trace.refs.ObjectRef]
  • dataset: “
  • scorers: typing.Optional[list[typing.Annotated[typing.Union[trace.op.Op, flow.scorer.Scorer], BeforeValidator(func=)]]]
  • preprocess_model_input: typing.Optional[typing.Callable[[dict], dict]]
  • trials: “
  • evaluation_name: typing.Union[str, typing.Callable[[trace.weave_client.Call], str], NoneType]

method evaluate​

classmethod from_obj​

method get_eval_results​

method predict_and_score​

method summarize​

class EvaluationLogger​

This class provides an imperative interface for logging evaluations. An evaluation is started automatically when the first prediction is logged using the log_prediction method, and finished when the log_summary method is called. Each time you log a prediction, you will get back a ScoreLogger object. You can use this object to log scores and metadata for that specific prediction. For more information, see the ScoreLogger class. Example:
Pydantic Fields:
  • name: str | None
  • model: flow.model.Model | dict | str
  • dataset: flow.dataset.Dataset | list[dict] | str

property ui_url​

method finish​

Clean up the evaluation resources explicitly without logging a summary. Ensures all prediction calls and the main evaluation call are finalized. This is automatically called if the logger is used as a context manager.

method log_prediction​

Log a prediction to the Evaluation, and return a reference. The reference can be used to log scores which are attached to the specific prediction instance.

method log_summary​

Log a summary dict to the Evaluation. This will calculate the summary, call the summarize op, and then finalize the evaluation, meaning no more predictions or scores can be logged.

class Scorer​

Pydantic Fields:
  • name: typing.Optional[str]
  • description: typing.Optional[str]
  • ref: typing.Optional[trace.refs.ObjectRef]
  • column_map: typing.Optional[dict[str, str]]

method model_post_init​

method score​

method summarize​

class AnnotationSpec​

Pydantic Fields:
  • name: typing.Optional[str]
  • description: typing.Optional[str]
  • field_schema: dict[str, typing.Any]
  • unique_among_creators: “
  • op_scope: typing.Optional[list[str]]

classmethod preprocess_field_schema​

classmethod validate_field_schema​

method value_is_valid​

Validates a payload against this annotation spec’s schema. Args:
  • payload**: The data to validate against the schema
Returns:
  • bool: True if validation succeeds, False otherwise

class File​

A class representing a file with path, mimetype, and size information.

method __init__​

Initialize a File object. Args:
  • path**: Path to the file (string or pathlib.Path)
  • mimetype: Optional MIME type of the file - will be inferred from extension if not provided

property filename​

Get the filename of the file. Returns:
  • str: The name of the file without the directory path.

method open​

Open the file using the operating system’s default application. This method uses the platform-specific mechanism to open the file with the default application associated with the file’s type. Returns:
  • bool**: True if the file was successfully opened, False otherwise.

method save​

Copy the file to the specified destination path. Args:
  • dest**: Destination path where the file will be copied to (string or pathlib.Path) The destination path can be a file or a directory.

class Markdown​

A Markdown renderable. Args:
  • markup (str): A string containing markdown.
  • code_theme (str, optional): Pygments theme for code blocks. Defaults to “monokai”.
  • justify (JustifyMethod, optional): Justify value for paragraphs. Defaults to None.
  • style (Union[str, Style], optional): Optional style to apply to markdown.
  • hyperlinks (bool, optional): Enable hyperlinks. Defaults to True.
  • inline_code_lexer: (str, optional): Lexer to use if inline code highlighting is enabled. Defaults to None.
  • inline_code_theme: (Optional[str], optional): Pygments theme for inline code highlighting, or None for no highlighting. Defaults to None.

method __init__​

class Monitor​

Sets up a monitor to score incoming calls automatically. Examples:
Pydantic Fields:
  • name: typing.Optional[str]
  • description: typing.Optional[str]
  • ref: typing.Optional[trace.refs.ObjectRef]
  • sampling_rate: “
  • scorers: list[flow.scorer.Scorer]
  • op_names: list[str]
  • query: typing.Optional[trace_server.interface.query.Query]
  • active: “

method activate​

Activates the monitor. Returns: The ref to the monitor.

method deactivate​

Deactivates the monitor. Returns: The ref to the monitor.

classmethod from_obj​

class SavedView​

A fluent-style class for working with SavedView objects.

method __init__​

property entity​

property label​

property project​

property view_type​

method add_column​

method add_columns​

Convenience method for adding multiple columns to the grid.

method add_filter​

method add_sort​

method column_index​

method filter_op​

method get_calls​

Get calls matching this saved view’s filters and settings.

method get_known_columns​

Get the set of columns that are known to exist.

method get_table_columns​

method hide_column​

method insert_column​

classmethod load​

method page_size​

method pin_column_left​

method pin_column_right​

method remove_column​

method remove_columns​

Remove columns from the saved view.

method remove_filter​

method remove_filters​

Remove all filters from the saved view.

method rename​

method rename_column​

method save​

Publish the saved view to the server.

method set_columns​

Set the columns to be displayed in the grid.

method show_column​

method sort_by​

method to_grid​

method to_rich_table_str​

method ui_url​

URL to show this saved view in the UI. Note this is the “result” page with traces etc, not the URL for the view object.

method unpin_column​

class Audio​

A class representing audio data in a supported format (wav or mp3). This class handles audio data storage and provides methods for loading from different sources and exporting to files. Attributes:
  • format**: The audio format (currently supports ‘wav’ or ‘mp3’)
  • data: The raw audio data as bytes
Args:
  • data: The audio data (bytes or base64 encoded string)
  • format: The audio format (‘wav’ or ‘mp3’)
  • validate_base64: Whether to attempt base64 decoding of the input data
Raises:
  • ValueError: If audio data is empty or format is not supported

method __init__​

method export​

Export audio data to a file. Args:
  • path**: Path where the audio file should be written

classmethod from_data​

Create an Audio object from raw data and specified format. Args:
  • data**: Audio data as bytes or base64 encoded string
  • format: Audio format (‘wav’ or ‘mp3’)
Returns:
  • Audio: A new Audio instance
Raises:
  • ValueError: If format is not supported

classmethod from_path​

Create an Audio object from a file path. Args:
  • path**: Path to an audio file (must have .wav or .mp3 extension)
Returns:
  • Audio: A new Audio instance loaded from the file
Raises:
  • ValueError: If file doesn’t exist or has unsupported extension
Edit this pageLast updated on Jul 14, 2025